﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;
using System.Text;

namespace CardLogistics.Web.MainPage.PutOutCard.PutOutSendCard
{
    public partial class PutOutSendCardDetailsList : BasePage
    {
        /// <summary>
        /// 箱数
        /// </summary>
        public int BoxNumber
        {
            get;
            set;
        }
        /// <summary>
        /// 盒数
        /// </summary>
        public int CardNumber
        {
            get;
            set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDLL(ddlCardType, "basic_cardtype", "cardtypename", "id", " and  status<>1 and isdelete=0"); //卡片类型
                BindDLL(ddlLeadingUnit, "BASIC_SALESINFO", "SALESNAME", "Id", " and ISDELETE=0  ");//绑定芯片类型
                BindRpt(LoadStrWhere);
            }
        }

        /// <summary>
        /// 绑定Rpt数据
        /// </summary>
        private void BindRpt(string strWhere)
        {
            int recordCount = 0;
            int pageCount = 0;
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append(" 1=1 ");
            //发放单号
            if (!string.IsNullOrEmpty(this.txtSENDNO.Text.Trim()) && txtSENDNO.Text.Trim().Length > 0)
                sbStr.Append(" and SENDNO like '%" + txtSENDNO.Text.Trim().ToUpper() + "%' ");
            //出库单号
            if (!string.IsNullOrEmpty(this.txtPUTOUTCARDNO.Text.Trim()) && txtPUTOUTCARDNO.Text.Trim().Length > 0)
                sbStr.Append(" and PUTOUTCARDNO like '%" + txtPUTOUTCARDNO.Text.Trim().ToUpper() + "%' ");
            //销售网点
            if (this.ddlLeadingUnit.SelectedItem != null && ddlLeadingUnit.SelectedValue != "" && ddlLeadingUnit.SelectedValue != "0")
            {
                sbStr.Append(" and LEADINGUNIT='" + ddlLeadingUnit.SelectedValue + "'");
            }
            //卡类型
            if (this.ddlCardType.SelectedItem != null && ddlCardType.SelectedValue != "" && ddlCardType.SelectedValue != "0")
            {
                sbStr.Append(" and cardtypeId='" + ddlCardType.SelectedValue + "'");
            }
            if (txt_StartStorageDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(LEADINGDATE,'yyyy-MM-dd')>='" + txt_StartStorageDate.Text.Trim() + "'");//领用开始日期
            if (txt_EndStorageDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(LEADINGDATE,'yyyy-MM-dd')<='" + txt_EndStorageDate.Text.Trim() + "'");//领用结束日期
           
            if (!string.IsNullOrEmpty(strWhere))
            {
                sbStr.Append(strWhere);
            }
            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_putoutsendcard_detail", "ID", " SENDNO desc", AspNetPager1.PageSize, WebPageIndex, sbStr.ToString(), "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);

            #region 导出数据
            //导出语句
            string strExpSql = "select LEADINGDATE 领用日期,SENDNO 发放单号,PUTOUTCARDNO 出库单号,SALESNAME 销售网点,CARDNO 盒号,cardtypename 卡类型,FGVAMT 卡成本,STARTCARDNO 开始卡号,ENDCARDNO 结束卡号,DUENUMBER 应有数量,ACTUALNUMBER 实际数量 from v_putoutsendcard_detail where " + sbStr.ToString() + "order by SENDNO desc";
            if (!Page.IsClientScriptBlockRegistered("regExportSql"))
                Page.RegisterClientScriptBlock("regExportSql", "<script language=\"Javascript\">var qsql=\"" + Server.UrlEncode(strExpSql) + "\";</script>");
            #endregion
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt("");
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            WebPageIndex = 1;
            BindRpt("");
        }
    }
}